/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package batailledesardennes.game.entity.task;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author charly
 */
public class TaskManager {
   private final List<Task> taskQueue; //use methods from different interfaces

   public TaskManager() {
      taskQueue = new ArrayList<Task>();
   }

   public void update(int delta) {
      while (!taskQueue.isEmpty()) {
         Task task = taskQueue.get(0);
         if (task.update(delta)) {
            return;
         } else {
            taskQueue.remove(0);
         }
      }
   }

   public void addTask(Task task) {
      taskQueue.add(task);
   }

   public void pushTask(Task task) {
      taskQueue.add(0, task);
   }

   public void popTask() {
      if (taskQueue.isEmpty()) {
         return;
      }
      taskQueue.remove(0);
   }

   public void clearTasks() {
      taskQueue.clear();
   }

   public Task getFirstTask() {
      if (taskQueue.isEmpty()) {
         return null;
      }
      Task nextTask = taskQueue.get(0);
      return nextTask;
   }
}
